home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 280 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  102 lines

  1. Path: sun001.spd.dsccc.com!sun001!dthornto
  2. From: dthornto@aplo266.spd.dsccc.com (Duane Thornton)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: help on syntax
  5. Date: 03 Jan 1996 14:51:03 GMT
  6. Organization: none
  7. Message-ID: <DTHORNTO.96Jan3085103@aplo266.spd.dsccc.com>
  8. References: <96002.222728APCCU@CUNYVM.CUNY.EDU>
  9. NNTP-Posting-Host: aplo266.spd.dsccc.com
  10. In-reply-to: Paul Abrilla's message of Tue, 2 Jan 1996 22:27:28 EST
  11.  
  12. You are using the wrong syntax for the 'if' statement. The correct
  13. syntax for 'if' is: 
  14.  
  15.   if (expression)
  16.     statement1;
  17.   else
  18.     statement2;
  19.  
  20. Indentation does not force the statements following the 'if' to be
  21. part of statement1. You must enclose the statements in braces to force
  22. the proper association.
  23.  
  24.   if (expression)
  25.   {
  26.     statement1;
  27.     statement2;
  28.     .
  29.     .
  30.     .
  31.   } 
  32.   else
  33.   {
  34.     statement11;
  35.     statement12;
  36.     .
  37.     .
  38.     .
  39.   }
  40.  
  41. >>>>> On Tue, 2 Jan 1996 22:27:28 EST, Paul Abrilla <APCCU@CUNYVM.CUNY.EDU> said:
  42.  
  43.     [Snip]
  44.  
  45.     Paul> PROGRAM I
  46.  
  47.     Paul> #include <iostream.h>
  48.           #include <stdlib.h>
  49.           ^^^^^^^^^^^^^^^^^^^ To get return value
  50.     Paul> void main()
  51.           ^^^^ change to 'int main()'
  52.     Paul> {
  53.     Paul>       int a, b, c;
  54.     Paul>       cout << "Please enter three numbers¢n";
  55.     Paul>       cout << "a: ";
  56.     Paul>       cin >> a;
  57.     Paul>       cout << "¢nb: ";
  58.     Paul>       cin >> b;
  59.     Paul>       cout << "¢nc: ";
  60.     Paul>       cin >> c;
  61.     Paul>  
  62.     Paul>       if (c = (a-b))
  63.                      ^^^ change to '==' to test for equality
  64.                 {
  65.                ^^^ add a brace
  66.     Paul>           cout << "a: ";
  67.     Paul>           cout << a;
  68.     Paul>           cout << " minus b: ";
  69.     Paul>           cout << b;
  70.     Paul>           cout << " quals c: ";
  71.                              ^^ typo?
  72.     Paul>           cout << c << endl;
  73.                 }
  74.                ^^^ add a brace
  75.     Paul>       else
  76.     Paul>           cout << "a-b does not equal c: " << endl;
  77.     Paul>  
  78.             return EXIT_SUCCESS;
  79.             ^^^^^^^^^^^^^^^^^^^^ return value
  80.     Paul> }
  81.  
  82.  
  83.     [Snip]
  84.  
  85.     Paul> ----------- Paul email: apccu@cunyvm.cuny.edu
  86.  
  87.  
  88. -- 
  89. Duane 
  90.  
  91. ---------------------------- Duane Thornton --------------------------------
  92. Internet:  dthornto@spd.dsccc.com                       Opinions are my own.
  93. DSC Communications Corporation   Addr: MS 153, 1000 Coit Rd, Plano, TX 75075
  94. ----------------------------------------------------------------------------
  95. --
  96. Duane Thornton x94916 
  97.  
  98. ---------------------------- Duane Thornton --------------------------------
  99. Internet:  dthornto@spd.dsccc.com                       Opinions are my own.
  100. DSC Communications Corporation   Addr: MS 153, 1000 Coit Rd, Plano, TX 75075
  101. ----------------------------------------------------------------------------
  102.